//
//  PhotoResizerViewController.m
//  PrintFamily
//
//  Created by edaihua on 16/3/4.
//  Copyright © 2016年 ___PrintFactory___. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "PhotoResizerViewController.h"
#import "MasterViewController.h"
#import "PFPhoto.h"
#import "PFPhotoMaskView.h"
#import "PFPhotosManager.h"
#import "PhotoScrollView.h"

@import Photos;
@interface PhotoResizerViewController ()

@property (nonatomic, strong) PFPhotoMaskView *maskView;
@property (nonatomic, strong) PhotoScrollView *scrollView;

@end

@implementation PhotoResizerViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.maskView = [[PFPhotoMaskView alloc] initWithFrame:self.view.frame];
    self.maskView.backgroundColor = [UIColor clearColor];
    self.maskView.photo = self.photo;
    [self.view addSubview:self.maskView];

    self.scrollView = [[PhotoScrollView alloc] initWithFrame:self.view.frame];
    self.scrollView.photo = self.photo;
    [self.scrollView displayPhotoWithAsset:self.photo.asset];
    [self.view addSubview:self.scrollView];
    
    [self.view bringSubviewToFront:self.maskView];
    // Do any additional setup after loading the view.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - button gesture
- (IBAction)confirmTapped:(id)sender {
    [self.scrollView savePhotoResizeStatus];
    
    UIViewController *viewController = self.parentViewController;
    if ([viewController isKindOfClass:[MasterViewController class]]) {
        MasterViewController* masterController = (MasterViewController*)viewController;
        [masterController.tableView reloadData];
    }
    
    [self.tableView reloadData];
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)cancelTapped:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
